package org.codeart.serviceuser.controller;

import org.codeart.common.util.HttpStatus;
import org.codeart.common.dto.PassengerUser;
import org.codeart.common.util.R;
import org.codeart.common.dto.VerifyCodeDTO;
import org.codeart.serviceuser.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {
    
    @Autowired
    private UserService userService;

    @PostMapping
    public R<Void> registerUser(@RequestBody VerifyCodeDTO verifyCodeDTO) {
        String phone = verifyCodeDTO.getPassengerPhone();
        boolean b = userService.registerUser(phone);
        if (b) {
            return R.ok();
        }
        return R.fail();
    }
    
    @GetMapping
    public R<PassengerUser> getUserByPhone(@RequestParam("passengerPhone") String passengerPhone) {
        PassengerUser user = userService.getUserByPhone(passengerPhone);
        if (user == null) {
            R.fail(HttpStatus.HTTP_NOT_FOUND, "用户不存在");
        }
        return R.ok(user);
    }
    
    
    
}
